
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<form id="formId" method="post">
    用户名：<input type="text" name="name"/><br/>
    密码：<input type="text" name="password"/><br/>
    验证码：<input type="text" name="code"/>
    <img id="verigyCodeId" src="<%=request.getContextPath()%>/verifyCode" onclick="refresh()"/>
    <br/>
    <input type="button" onclick="submitForm()" value="登录"/>
</form>


<script src="<%=request.getContextPath()%>/static/mylayer.js" type="text/javascript" charset="utf-8"></script>
<script src="<%=request.getContextPath()%>/static/jquery-2.1.4.js" type="text/javascript" charset="utf-8"></script>
<script src="<%=request.getContextPath()%>/static/layer/layer.js" type="text/javascript" charset="utf-8"></script>
<script>
    function refresh() {
        $('#verigyCodeId').attr('src', '<%=request.getContextPath()%>/verifyCode?' + Math.random());
    }

    function submitForm() {
        $.post(
            '<%=request.getContextPath()%>/user?method=login',
            $('#formId').serialize(),
            function(jsonObj) {
                console.log(jsonObj);
                //{msg: '登录成功', code: 0}
                if (jsonObj.code == 0) {
                    mylayer.okUrl(jsonObj.msg, '<%=request.getContextPath()%>');
                } else {
                    mylayer.errorMsg(jsonObj.msg);
                }
            },
            'json'
        );
    }
</script>
</body>
</html>
